<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Model\Ad;
use App\Http\Model\Slide;
use App\Http\Model\Goods;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Http\Model\Type;


use DB;

class IndexController extends Controller
{
     /**
     * 处理前台分类数据
     */
    static public function getCatePid($pid=0)
    {

        $ctype = new Type();

        $data = $ctype->where('pid',$pid)->get();
        
        $arr = [];

        foreach ($data as $key => $value) {
            
            $value['sub'] = self::getCatePid($value['id']);

            $arr[] = $value;
        }
        return $arr;

    }




    /**
     * 前台主页面
     *
     * @return 前台主页
     */
    public function index($pid=0)
    {
        //
        /*===================搜索====================*/














        /*===================分类====================*/














        /*===================商品====================*/
          $goods = Goods::orderBy('count','desc')->take(12)->get();

         

         













          /*===================轮播====================*/
        $slide = Slide::orderBy('order','asc')->take(4)->get();


















        /*===================列表====================*/



















        /*===================广告====================*/
         $ad = Ad::orderBy('order','asc')->take(8)->get();




















       
















        /*===================友情链接====================*/
        $link = DB::table('sad_link')->orderBy('order','asc')->get();
        // dd($link);







        return view('home.index.index',['data'=>self::getCatePid(),'ad'=>$ad,'slide'=>$slide,'goods'=>$goods,'link'=>$link]);


    }

}
